﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace GeFIN
{
    public partial class mainForm : Form
    {
        LogInMenu logIn;
        janelaDeMensagens mensagem;

        public mainForm()
        {
            InitializeComponent();
            logIn = new LogInMenu();
            mensagem = new janelaDeMensagens();
        }

        private void sairDoProgramaToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void mainForm_Load(object sender, EventArgs e)
        {
            // TODO: This line of code loads data into the 'geFINSystemDataSet.Conta' table. You can move, or remove it, as needed.
            this.contaTableAdapter.Fill(this.geFINSystemDataSet.Conta);
            //if ((contaBindingSource.List.Count - 1) == contaBindingSource.Position) contaBindingSource.MoveFirst();
            //else contaBindingSource.MoveNext();
            MessageBox.Show("contaBindingSource.Position: "+contaBindingSource.Position.ToString());

            logIn.showDialog(contaBindingSource.Position);
            mensagem.ShowDialog();
        }

        private void editarToolStripMenuItem_Click(object sender, EventArgs e)
        {
            cadastroConta janelaDaConta = new cadastroConta();
            janelaDaConta.exibirAlteracao(contaBindingSource.DataSource, contaBindingSource.DataMember, contaBindingSource.Position);

            if (janelaDaConta.DialogResult == DialogResult.OK) contaTableAdapter.Update(geFINSystemDataSet.Conta);
        }

        private void sairToolStripMenuItem_Click(object sender, EventArgs e)
        {
            logIn.showDialog(contaBindingSource.Position);
        }

        private void mainForm_FormClosed(object sender, FormClosedEventArgs e)
        {
            logIn.disconnect();
        }

        private void excluirToolStripMenuItem_Click(object sender, EventArgs e)
        {
            DialogResult confirmacao = MessageBox.Show("Deseja realmente excluir sua conta e apagar todos os seus dados financeiros?", "Exclusão de Conta", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
            if (confirmacao == DialogResult.Yes)
            {
                contaBindingSource.RemoveCurrent();
                contaTableAdapter.Update(geFINSystemDataSet.Conta);

                //falta apagar todos os dados relacionados a essa conta
            }
        }
    }
}
